package com.his.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.admin.service.InterfaceService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.Hospital;
import com.his.dao.domain.entity.MInterface;
import com.his.dao.domain.entity.Role;
import com.his.dao.domain.vo.ListVo;
import com.his.dao.mapper.InterfaceMapper;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import com.his.util.util.MapUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fall
 * @since 2022-11-28
 */
@Service
@AllArgsConstructor
public class InterfaceServiceImpl extends ServiceImpl<InterfaceMapper, MInterface> implements InterfaceService {
    private InterfaceMapper interfaceMapper;

    @Override
    public RestResult all(ListDto listDto) {
        MInterface mInterface = MapUtil.conversionMapToObj((LinkedHashMap) listDto.getObj(), MInterface.class);
        IPage iPage = new Page(listDto.getPage(), listDto.getPageSize());
        QueryWrapper<MInterface> queryWrapper = new QueryWrapper<MInterface>()
                .like(mInterface.getName() != null, "name", mInterface.getName())
                .like(mInterface.getUrl() != null, "url", mInterface.getUrl())
                .eq(mInterface.getIsOpen() != null, "is_open", mInterface.getIsOpen());
        IPage page = interfaceMapper.selectPage(iPage, queryWrapper);

        return new RestResultBuilder().success(ListVo
                .builder()
                .list(page.getRecords())
                .total(page.getTotal())
                .build());
    }
}
